<template>
    <div class="table store sever_list">
        <div class="crumbs store_title">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>组员管理</el-breadcrumb-item>
            </el-breadcrumb>
            <div class="mainBtn-block">
                <!-- <div class="mainBtn">
                    <span>表单接收：</span>
                    <el-switch v-model="tableStatus" active-color="#13ce66" inactive-color="#ff4949"></el-switch>
                </div>-->
                <div class="mainBtn">
                    <el-button type="success" @click="addStore()">门店情况</el-button>
                </div>
            </div>
        </div>
        <div class="container">
            <div v-if="roleName=='咨询主管'" style="display: inline-block">
                <el-select v-model="groupId" @change="reallyGroup" class="ex_input_city">
                    <el-option v-for="items in groupList" :key="items.id" :label="items.name" :value="items.id"></el-option>
                </el-select>
            </div>
            <el-select style="margin-top: 10px;width: 120px;" @change="timeSelectFn" v-model="searchTime" placeholder="时间类型">
                <el-option label="下单时间" value="ORDERTIME"></el-option>
                <el-option label="操作时间" value="ORERATIONTIME"></el-option>
            </el-select>
            <el-date-picker :clearable="false" v-model="findStartTimeValue" @change="dataSelectFn" :picker-options="pickerOptDef" type="datetimerange" style="margin-bottom: 20px" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
            <el-table v-if="activeShow" :data="list" border style="width: 100%;margin-top: 20px;" ref="multipleTable" show-summary :summary-method="getSummaries" @selection-change="handleSelectionChange">
                <el-table-column prop="name" label="姓名" :filters="listname" :filter-method="filterHandler" width="180px"></el-table-column>
                <el-table-column prop="status" label="是否启用"></el-table-column>
                <el-table-column prop="dereceiveNum" label="客户总数"></el-table-column>
                <el-table-column prop="receiveNum" label="未跟踪"></el-table-column>
                <el-table-column prop="addWechatNum" label="加微数"></el-table-column>
                <el-table-column prop="addWechatSurpriseNum" label="额外加微数"></el-table-column>
                <el-table-column prop="invalidNum" label="无效数"></el-table-column>
                <el-table-column prop="tailAfterNum" label="跟踪数"></el-table-column>
                <el-table-column prop="rate" label="通过率"></el-table-column>
                <el-table-column prop="rateAll" label="总通过率"></el-table-column>
                <el-table-column label="操作" align="center" width="260">
                    <template slot-scope="scope">
                        <el-button size="small" type="primary" @click="bandFn(scope.$index, scope.row)">详情</el-button>
                        <el-button size="small" type="primary" @click="readFn(scope.$index, scope.row)">修改详情</el-button>
                        <el-button size="small" type="primary" @click="editFn(scope.$index, scope.row)">修改</el-button>
                        <!--<el-button size="small" type="primary" @click="editFn(scope.$index, scope.row)">加库存</el-button>-->
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <!-- 门店情况 -->
        <el-dialog :visible.sync="addStoreDialog" width="900px">
            <el-select style="margin-top: 10px;width: 120px;" @change="timeStoreFn" v-model="StoreTime" placeholder="时间类型">
                <el-option label="下单时间" value="ORDERTIME"></el-option>
                <el-option label="操作时间" value="ORERATIONTIME"></el-option>
            </el-select>
            <el-date-picker :clearable="false" v-model="TimeValue" @change="dataStoreFn" type="datetimerange" :picker-options="pickerOptDef" style="margin-bottom: 20px" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
            <el-table v-if="activeShow" :data="detailStore" border style="width: 100%;" show-summary :summary-method="getSummariesStore" ref="multipleTable" @selection-change="handleSelectionChange">
                <el-table-column prop="shopName" label="店名" width="200px" :filters="listshopName" :filter-method="filterHandler"></el-table-column>
                <el-table-column prop="dereceiveNum" label="客户总数"></el-table-column>
                <el-table-column prop="receiveNum" label="未跟踪"></el-table-column>
                <el-table-column prop="addWechatNum" label="加微数"></el-table-column>
                <el-table-column prop="addWechatSurpriseNum" label="额外加微数"></el-table-column>
                <el-table-column prop="invalidNum" label="无效数"></el-table-column>
                <el-table-column prop="tailAfterNum" label="跟踪数"></el-table-column>
                <el-table-column prop="rate" label="通过率"></el-table-column>
                <el-table-column prop="rateAll" label="总通过率"></el-table-column>
            </el-table>
            <!--<div class="pagination">-->
            <!--<el-pagination-->
            <!--@current-change="handleCurrentChange"-->
            <!--@size-change="handleSizeChange"-->
            <!--layout="total, prev, pager, next"-->
            <!--:total="pageNum"-->
            <!--:page-size="pageSize"-->
            <!--:current-page="cur_page">-->
            <!--</el-pagination>-->
            <!--</div>-->
        </el-dialog>

        <!-- 弹出框 -->
        <el-dialog :visible.sync="addMemberDialog" :width="data_extend.length>1 ? '700px': '500px'">
            <el-form label-width="120px" ref="memberData" :v-model="memberData" class="extend_form">
                <el-form-item label="员工姓名：">
                    <span v-html="memberData.name"></span>
                </el-form-item>
                <el-form-item label="是否启用：">
                    <div>
                        <el-radio-group @change="showStatus" v-model="Mstatus">
                            <el-radio-button label="否"></el-radio-button>
                            <el-radio-button label="是"></el-radio-button>
                        </el-radio-group>
                        <div slot="tip" class="ex_input_tip">注：不启用，不分配</div>
                    </div>
                </el-form-item>
                <el-form-item label="负责门店：">
                    <div>
                        <el-button type="primary" @click="addData_ex">添加负责门店</el-button>
                    </div>
                    <div class="ex_parent" v-for="(item, index) in data_extend" :key="index">
                        <div>
                            <span style="display:inline-block;width: 80px;text-align: right;">负责门店：</span>
                            <el-select v-model="item.shopId" @change="reallyStore" style="width: 120px;">
                                <el-option v-for="items in storeList" :key="items.id" :label="items.shopName" :value="items.id"></el-option>
                            </el-select>
                        </div>
                        <div>
                            <span style="display:inline-block;width: 80px;text-align: right;">分配数：</span>
                            <el-input v-model="item.quota" style="width: 120px;"></el-input>
                        </div>
                        <div>
                            <span style="display:inline-block;width: 80px;text-align: right;">优先级：</span>
                            <el-input v-model="item.ranking" style="width: 120px;"></el-input>
                        </div>
                        <div v-if="item.residue == 0">
                            <span style="display:inline-block;width: 80px;text-align: right;">剩余额度：</span>
                            <el-input v-model="item.residue" style="width: 120px;"></el-input>
                            <i class="el-icon-warning" style="color: red"></i>
                        </div>
                        <div v-else>
                            <span style="display:inline-block;width: 80px;text-align: right;">剩余额度：</span>
                            <el-input v-model="item.residue" style="width: 120px;border: 1px solid red; border-radius: 5px;"></el-input>
                        </div>
                        <div>
                            <el-button type="primary" @click="delData_ex(item,index)">删除</el-button>
                            <el-button style="margin-left: 24px;" v-if="item.residue != 0" type="warning" @click="delAmount(item,index)">删除额度</el-button>
                        </div>
                    </div>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="addMemberDialog = false">取 消</el-button>
                <el-button type="primary" @click="saveEdit()">确 定</el-button>
            </span>
        </el-dialog>

        <el-dialog :visible.sync="readMemberDialog" :width="data_extend.length>1 ? '728px': '528px'">
            <el-form label-width="120px" ref="memberData" :v-model="memberData" class="extend_form">
                <el-form-item label="员工姓名：">
                    <span v-html="memberData.name"></span>
                </el-form-item>
                <el-form-item label="是否启用：">
                    <el-tag v-html="Mstatus"></el-tag>
                </el-form-item>
                <el-form-item label="负责门店：">
                    <div class="ex_parent" v-for="(item, index) in data_extend" :key="index">
                        <div>
                            <span style="display:inline-block;width: 80px;text-align: right;">负责门店：</span>
                            <el-select v-model="item.shopId" @change="reallyStore" style="width: 120px;" disabled>
                                <el-option v-for="items in storeList" :key="items.id" :label="items.shopName" :value="items.id"></el-option>
                            </el-select>
                        </div>
                        <div>
                            <span style="display:inline-block;width: 80px;text-align: right;">分配数：</span>
                            <el-input v-model="item.quota" style="width: 120px;" disabled></el-input>
                        </div>
                        <div>
                            <span style="display:inline-block;width: 80px;text-align: right;">优先级：</span>
                            <el-input v-model="item.ranking" style="width: 120px;" disabled></el-input>
                        </div>
                        <div>
                            <span style="display:inline-block;width: 80px;text-align: right;">剩余额度：</span>
                            <el-input v-model="item.residue" style="width: 120px;" disabled></el-input>
                        </div>
                    </div>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="readMemberDialog = false">关 闭</el-button>
                <!-- <el-button @click="readMemberDialog = false">确 定</el-button> -->
            </span>
        </el-dialog>
    </div>
</template>

<script>
import { groupList, storeAsGet, storeAsPost, storeAsPut } from "../api/api"
import { formatDate } from "../tool/tool"
import { base64, tool_confirm } from "../tool/tool"
export default {
    data() {
        return {
            //时间类型
            searchTime: "ORDERTIME",
            //列表数据
            list: [],
            listname: [],
            listshopName: [],
            salcTotalObj: {},
            salcListTotalObj: {},
            //分页
            pageNum: null,
            cur_page: 0,
            pageSize: 10,
            //弹窗
            addStoreDialog: false,
            addMemberDialog: false,
            readMemberDialog: false,
            // 添加负责区域
            data_extend: [],
            //门店
            storeList: [],
            // 组员设置信息
            memberData: {},
            Mstatus: "",
            statusData: "",
            // memberSettingForm: {
            //     status: '',
            //     counselorShopRelationList: [],
            // },
            trueForm: {},
            memeberID: "",
            groupList: [],
            groupId: "",
            roleName: "",
            activeShow: false,
            findStartTimeValue: "",
            startTime: "",
            endTime: "",
            detailStore: [],
            StoreTime: "ORDERTIME",
            // storePage: 0,
            storeStart: "",
            storeEnd: "",
            TimeValue: "",
            // 表单接收状态
            tableStatus: false
        }
    },
    created() {
        // console.log(localStorage.getItem('roleName'),"created")
        if (localStorage.getItem("roleName") == "咨询主管") {
            this.getGroupList()
        }
        this.dataSelectFn()
        this.getStoreList()
        this.dataStoreFn()
        this.getStoreDetail()
        this.getMemberList()
    },
    computed: {},
    methods: {
        getGroupList() {
            console.log(localStorage.getItem("roleName"), "roleName")
            groupList()
                .then(res => {
                    // 赋值
                    this.groupList = res.data.content.list
                    if (this.groupList.length > 0) {
                        // console.log(this.groupList,"this.groupList")

                        this.groupId = this.groupList[0].id
                        console.log(this.groupId)
                        this.getMemberList()
                        this.getStoreList()
                        this.getStoreDetail()
                    }
                })
                .catch(errors => {
                    this.$message.error(errors.response.data.detail)
                })
        },
        filterHandler(value, row, column) {
            const property = column["property"]
            return row[property] === value
        },
        dataSelectFn(data) {
            //日期搜索预约列表
            let startTime =
                formatDate(new Date(), "yyyy-MM-dd hh:mm:ss").substring(0, 10) +
                " 00:00:00"
            let endTime = formatDate(new Date(), "yyyy-MM-dd hh:mm:ss").substring(0, 10) + " 23:59:59"
            if (!data) {
                let data = []
                data[0] = startTime
                data[1] = endTime
                this.startTime = data[0]
                this.endTime = data[1]
                this.findStartTimeValue = data
            } else {
                this.startTime = formatDate(data[0], "yyyy-MM-dd hh:mm:ss")
                this.endTime = formatDate(data[1], "yyyy-MM-dd hh:mm:ss")
            }
            this.getMemberList()

            console.log(this.findStartTimeValue, "findStartTimeValue")
        },
        reallyGroup(val) {
            console.log(val, "reallyGroup")
            this.getMemberList()
            this.getStoreList()
            this.getStoreDetail()
        },
        // 组员列表
        getMemberList() {
            this.activeShow = false
            this.$nextTick(function() {
                this.activeShow = true
            })
            if (this.groupId == "" && localStorage.getItem("roleName") == "咨询主管") {
                return false
             }
            let hostUrl = (localStorage.getItem("roleName") == "咨询主管")? 
                        "/counselor/list/dept?counselorDeptId=" + this.groupId + "&startTime=" + this.startTime + "&endTime=" + this.endTime + "&timeType=" + this.searchTime :
                        "/counselor/list/dept?counselorDeptId=&direction=DESC&propertys=name&startTime=" + this.startTime + "&endTime=" + this.endTime + "&timeType=" + this.searchTime
                    storeAsGet(hostUrl).then(res => {
                            // console.log(res,"Member")
                            this.list = res.data.content.list

                            this.salcListTotalObj = {
                                addWechatNumAll : 0,
                                dereceiveNumAll : 0,
                                invalidNumAll : 0,
                                receiveNumAll: 0,
                                tailAfterNumAll: 0,
                                addWechatSurpriseNumAll: 0,
                            }
                            Array.prototype.slice.call(this.list).forEach((value, index) => {
                                    //客户总数dereceiveNum
                                    value.dereceiveNum = value.receiveNum + value.addWechatNum + value.invalidNum + value.tailAfterNum + value.addWechatSurpriseNum
                                    let rateMon = value.dereceiveNum - value.invalidNum

                                    this.salcListTotalObj.addWechatNumAll += value.addWechatNum
                                    this.salcListTotalObj.addWechatSurpriseNumAll += value.addWechatSurpriseNum
                                    this.salcListTotalObj.dereceiveNumAll += value.dereceiveNum
                                    this.salcListTotalObj.invalidNumAll += value.invalidNum
                                    this.salcListTotalObj.tailAfterNumAll += value.tailAfterNum
                                    this.salcListTotalObj.receiveNumAll += value.receiveNum

                                    if (rateMon == 0 || value.dereceiveNum == 0) {
                                        value.rate = Number(0).toFixed(2) + "%"
                                        value.rateAll =
                                            Number(0).toFixed(2) + "%"
                                    } else {
                                        value.rate = Number(((value.addWechatNum + value.addWechatSurpriseNum) / (value.dereceiveNum - value.invalidNum)) * 100).toFixed(2) + "%"
                                        value.rateAll = Number(((value.addWechatNum + value.addWechatSurpriseNum) / value.dereceiveNum) * 100).toFixed(2) + "%"
                                    }
                                    switch (value.status) {
                                        case "DISABLED":
                                            value.status = "否"
                                            break
                                        case "NORMAL":
                                            value.status = "是"
                                            break
                                    }
                                })
                                
                            this.listname = []
                            this.list.map(item => {
                                this.listname.push({
                                    text: item.name,
                                    value: item.name
                                })
                            })
                            console.log(this.list, "this.list331")
                        })
                        .catch(errors => {
                            this.$message.error(errors.response.data.detail)
                        })
        },
        // 时间类型
        timeSelectFn(val) {
            this.searchTime = val
            this.getMemberList()
        },
        // 门店列表
        getStoreList() {
            this.roleName = localStorage.getItem("roleName")
            let hostUrl = (localStorage.getItem("roleName") == "咨询主管")? "/counselorDept/shop/relation/list/dept?counselorDeptId=" + this.groupId : "/counselorDept/shop/relation/list/dept?counselorDeptId="
                storeAsGet(hostUrl)
                    .then(res => {
                        console.log(res.data.content.list, "Store")
                        this.storeList = res.data.content.list

                        this.salcTotalObj = {
                                addWechatNumAll : 0,
                                dereceiveNumAll : 0,
                                invalidNumAll : 0,
                                receiveNumAll: 0,
                                tailAfterNumAll: 0,
                                addWechatSurpriseNumAll: 0,
                        }

                        Array.prototype.slice.call(this.storeList).forEach((value, index) => {
                                value.dereceiveNum = value.receiveNum + value.addWechatNum + value.invalidNum + value.tailAfterNum + value.addWechatSurpriseNum
                                let rateMon = value.dereceiveNum - value.invalidNum
                                
                                this.salcTotalObj.addWechatNumAll += value.addWechatNum
                                this.salcTotalObj.addWechatSurpriseNumAll += value.addWechatSurpriseNum
                                this.salcTotalObj.dereceiveNumAll += value.dereceiveNum
                                this.salcTotalObj.invalidNumAll += value.invalidNum
                                this.salcTotalObj.tailAfterNumAll += value.tailAfterNum
                                this.salcTotalObj.receiveNumAll += value.receiveNum

                                if (rateMon == 0 || value.dereceiveNum == 0) {
                                    value.rate = Number(0).toFixed(2) + "%"
                                    value.rateAll = Number(0).toFixed(2) + "%"
                                } else {
                                    value.rate = Number(((value.addWechatNum + value.addWechatSurpriseNum) / (value.dereceiveNum - value.invalidNum)) * 100).toFixed(2) + "%"
                                    value.rateAll = Number(((value.addWechatNum + value.addWechatSurpriseNum) / value.dereceiveNum) * 100).toFixed(2) + "%"
                                }
                            })
                    })
                    .catch(errors => {
                        this.$message.error(errors.response.data.detail)
                    })

        },
        timeStoreFn(val) {
            this.StoreTime = val
            this.getStoreDetail()
        },
        dataStoreFn(data) {
            //日期搜索预约列表
            let startTime =
                formatDate(new Date(), "yyyy-MM-dd hh:mm:ss").substring(0, 10) +
                " 00:00:00"
            let endTime = formatDate(new Date(), "yyyy-MM-dd hh:mm:ss").substring(0, 10) + " 23:59:59"
            if (!data) {
                let data = []
                data[0] = startTime
                data[1] = endTime
                this.storeStart = data[0]
                this.storeEnd = data[1]
                this.TimeValue = data
            } else {
                this.storeStart = formatDate(data[0], "yyyy-MM-dd hh:mm:ss")
                this.storeEnd = formatDate(data[1], "yyyy-MM-dd hh:mm:ss")
            }
            this.getStoreDetail()
        },
        //门店详情
        getStoreDetail() {
            this.roleName = localStorage.getItem("roleName")
            let hostUrl = (this.roleName == "咨询主管")? "/counselorDept/shop/relation/list/shop?timeType=" + this.StoreTime + "&direction=DESC&propertys=createdTime&counselorDeptId="+ this.groupId + "&startTime=" + this.storeStart + "&endTime=" + this.storeEnd :
                          "/counselorDept/shop/relation/list/shop?timeType=" + this.StoreTime + "&direction=DESC&propertys=createdTime&counselorDeptId=" + "&startTime=" + this.storeStart + "&endTime=" + this.storeEnd
                storeAsGet(hostUrl)
                    .then(res => {
                        console.log(res.data.content.list, "Store")
                        this.detailStore = res.data.content.list

                        this.salcTotalObj = {
                                addWechatNumAll : 0,
                                dereceiveNumAll : 0,
                                invalidNumAll : 0,
                                receiveNumAll: 0,
                                tailAfterNumAll: 0,
                                addWechatSurpriseNumAll: 0,
                        }

                        Array.prototype.slice
                            .call(this.detailStore)
                            .forEach((value, index) => {
                                value.dereceiveNum = value.receiveNum + value.addWechatNum + value.invalidNum + value.tailAfterNum + value.addWechatSurpriseNum
                                let rateMon = value.dereceiveNum - value.invalidNum
                                
                                this.salcTotalObj.addWechatNumAll += value.addWechatNum
                                this.salcTotalObj.addWechatSurpriseNumAll += value.addWechatSurpriseNum
                                this.salcTotalObj.dereceiveNumAll += value.dereceiveNum
                                this.salcTotalObj.invalidNumAll += value.invalidNum
                                this.salcTotalObj.tailAfterNumAll += value.tailAfterNum
                                this.salcTotalObj.receiveNumAll += value.receiveNum

                                if (rateMon == 0 || value.dereceiveNum == 0) {
                                    value.rate = Number(0).toFixed(2) + "%"
                                    value.rateAll = Number(0).toFixed(2) + "%"
                                } else {
                                    value.rate = Number(((value.addWechatNum + value.addWechatSurpriseNum) / (value.dereceiveNum - value.invalidNum)) * 100).toFixed(2) + "%"
                                    value.rateAll = Number(((value.addWechatNum+ value.addWechatSurpriseNum) / value.dereceiveNum) * 100).toFixed(2) + "%"
                                }
                            })
                        this.listshopName = []
                        this.detailStore.map(item => {
                            this.listshopName.push({
                                text: item.shopName,
                                value: item.shopName
                            })
                        })
                    })
                    .catch(errors => {
                        this.$message.error(errors.response.data.detail)
                    })
        },
        //修改员工设置
        editFn(e, val) {
            this.addMemberDialog = true
            console.log(e, val)
            this.memeberID = val.id
            let newData = []
            this.data_extend = []
            storeAsGet("/counselor/detail?counselorId=" + val.id)
                .then(res => {
                    console.log(
                        res.data.content.detail.counselorShopRelationList,
                        "editFn"
                    )
                    this.memberData = res.data.content.detail
                    newData = res.data.content.detail.counselorShopRelationList
                    newData.map(item => {
                        // console.log(item)
                        this.data_extend.push({
                            shopId: item.shop.id,
                            ranking: item.ranking,
                            quota: item.quota,
                            residue: item.residue
                        })
                    })
                    if (res.data.content.detail.status == "NORMAL") {
                        this.Mstatus = "是"
                        this.statusData = "NORMAL"
                    } else {
                        this.Mstatus = "否"
                        this.statusData = "DISABLED"
                    }
                })
                .catch(errors => {
                    this.$message.error(errors.response.data.detail)
                })
        },
        readFn(e, val) {
            this.readMemberDialog = true
            let newData = []
            this.data_extend = []
            storeAsGet("/counselor/detail?counselorId=" + val.id)
                .then(res => {
                    console.log(
                        res.data.content.detail.counselorShopRelationList,
                        "editFn"
                    )
                    this.memberData = res.data.content.detail
                    newData = res.data.content.detail.counselorShopRelationList
                    newData.map(item => {
                        // console.log(item)
                        this.data_extend.push({
                            shopId: item.shop.id,
                            ranking: item.ranking,
                            quota: item.quota,
                            residue: item.residue
                        })
                    })
                    if (res.data.content.detail.status == "NORMAL") {
                        this.Mstatus = "是"
                        this.statusData = "NORMAL"
                    } else {
                        this.Mstatus = "否"
                        this.statusData = "DISABLED"
                    }
                })
                .catch(errors => {
                    this.$message.error(errors.response.data.detail)
                })
        },
        // 是否启用状态
        showStatus(e) {
            console.log(e, "启用")
            if (e === "是") {
                this.statusData = "NORMAL"
            } else {
                // this.returnTableFlag = false;
                this.statusData = "DISABLED"
            }
        },
        reallyStore(val) {
            console.log(val, "reallyStore")
        },
        //添加负责区域
        addData_ex() {
            this.data_extend.push({
                shopId: "",
                ranking: "",
                quota: "",
                residue: ""
            })
            console.log("addData_ex")
        },
        //删除负责区域
        delData_ex(item, index) {
            // console.log(item, index,"item, index")
            console.log(this.data_extend, "before")
            for (var i = 0; i < this.data_extend.length; i++) {
                if (this.data_extend.length >= 0) {
                    if (index == i) {
                        if (this.data_extend[index]) {
                            this.data_extend[index].shopId = ""
                            this.data_extend[index].ranking = ""
                            this.data_extend[index].quota = ""
                            this.data_extend[index].residue = ""
                        }
                        this.data_extend.splice(i, 1)
                        console.log(this.data_extend, "after")
                    }
                }
            }
        },
        // 保存编辑
        saveEdit() {
            let expendData = {}
            let expendArr = []
            if (this.data_extend) {
                this.data_extend.map(item => {
                    expendData = {
                        ranking: item.ranking,
                        quota: item.quota,
                        residue: item.residue,
                        shop: {
                            id: ""
                        }
                    }
                    this.$set(expendData.shop, "id", item.shopId)
                    expendArr.push(expendData)
                })
            }
            console.log(expendArr, "'saveEdit'")

            this.trueForm = {
                status: this.statusData,
                counselorShopRelationList: expendArr
            }
            storeAsPut(
                "/counselor/detail?counselorId=" + this.memeberID,
                this.trueForm
            )
                .then(res => {
                    this.addMemberDialog = false
                    this.$message.success(`修改成功`)
                    this.getMemberList()
                })
                .catch(errors => {
                    this.$message.error(errors.response.data.detail)
                })
            console.log(this.trueForm, "trueForm265")
        },
        //查看详情
        bandFn(e, val) {
            console.log(e, val)
            if (localStorage.getItem("roleName") == "咨询主管") {
                this.$router.push({
                    path: "/extendDetail",
                    query: {
                        id: val.id,
                        groupid: this.groupId
                    }
                })
            } else {
                this.$router.push({
                    path: "/extendDetail",
                    query: {
                        id: val.id
                    }
                })
            }
        },

        // 分页导航
        handleCurrentChange(val) {
            this.cur_page = val
            // this.getStoreList(val-1)
        },
        addStore() {
            this.addStoreDialog = true
            this.activeShow = false
            this.$nextTick(function() {
                this.activeShow = true
            })
            console.log("新增")
            /* 点击触发 */
            this.getStoreList()
            this.dataStoreFn()

        },
        handleSelectionChange(val) {
            console.log(val, "handleSelectionChange")
            // this.multipleSelection = val;
        },
        handleSizeChange(val) {
            console.log(val, 111111)
        },
        /* 删除剩余额度 */
        delAmount(data, index) {
            data.residue = 0
        },
        /* 重写计算总数 */
        getSummaries(param) {
            const { columns, data } = param
            const sums = []
            columns.forEach((column, index) => {
                if (index === 0) {
                    sums[index] = "合计"
                    return
                }
                if(column.property == 'landPageUrl'){
                    sums[index] = ""
                    return
                }
                
                /* 计算成交率的 key 标识 */
                if (column.property == "rate" || column.property == "rateAll") {
                    let totalObj = this.salcListTotalObj
                    if(!totalObj){
                        return false
                    }
                    let temp = totalObj.dereceiveNumAll - totalObj.invalidNumAll
                    let tempAll = totalObj.dereceiveNumAll
                    if(column.property == "rate"){
                        console.log()
                        if(temp == 0){
                            sums[index] = '0.00%'
                            return 
                        }
                        sums[index] = Number(((totalObj.addWechatNumAll + totalObj.addWechatSurpriseNumAll) / temp) * 100 ).toFixed(2) + "%"
                                
                    }else{
                        if(tempAll == 0){
                            sums[index] = '0.00%'
                            return 
                        }
                        sums[index] = Number(((totalObj.addWechatNumAll + totalObj.addWechatSurpriseNumAll) / tempAll) * 100).toFixed(2) + "%"
                    }
                    return
                }
                const values = data.map(item => Number(item[column.property]))
                if (!values.every(value => isNaN(value))) {
                    sums[index] = values.reduce((prev, curr) => {
                        const value = Number(curr)
                        if (!isNaN(value)) {
                            return prev + curr
                        } else {
                            return prev
                        }
                    }, 0)
                    sums[index] += ""
                } else {
                    sums[index] = ""
                }
            })

            return sums
        },
        getSummariesStore(param) {
            const { columns, data } = param
            const sums = []
            columns.forEach((column, index) => {
                if (index === 0) {
                    sums[index] = "合计"
                    return
                }
                if(column.property == 'landPageUrl'){
                    sums[index] = ""
                    return
                }
                
                /* 计算成交率的 key 标识 */
                if (column.property == "rate" || column.property == "rateAll") {
                    let totalObj = this.salcTotalObj
                    if(!totalObj){
                        return false
                    }
                    let temp = totalObj.dereceiveNumAll - totalObj.invalidNumAll
                    let tempAll = totalObj.dereceiveNumAll
                    if(column.property == "rate"){
                        console.log()
                        if(temp == 0){
                            sums[index] = '0.00%'
                            return 
                        }
                        sums[index] = Number(((totalObj.addWechatNumAll + totalObj.addWechatSurpriseNumAll) / temp) * 100 ).toFixed(2) + "%"
                                
                    }else{
                        if(tempAll == 0){
                            sums[index] = '0.00%'
                            return 
                        }
                        sums[index] = Number(((totalObj.addWechatNumAll + totalObj.addWechatSurpriseNumAll) / tempAll) * 100).toFixed(2) + "%"
                    }
                    return
                }
                const values = data.map(item => Number(item[column.property]))
                if (!values.every(value => isNaN(value))) {
                    sums[index] = values.reduce((prev, curr) => {
                        const value = Number(curr)
                        if (!isNaN(value)) {
                            return prev + curr
                        } else {
                            return prev
                        }
                    }, 0)
                    sums[index] += ""
                } else {
                    sums[index] = ""
                }
            })

            return sums
        },
    }
}
</script>

<style scoped>
.store {
    position: relative;
}
.store .store_title {
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.store .store_title div {
    line-height: 40px;
}
.store .mainBtn-block {
    display: flex;
    align-items: center;
}
.store .mainBtn {
    margin-left: 60px;
    position: relative;
    /* position: absolute;
    right: 0;
    top: 0; */
}
.extend_form .ex_input {
    width: 300px;
}
.ex_input_city {
    width: 150px;
}
.ex_parent {
    width: 234px;
    padding: 10px;
    display: inline-block;
    border: 1px solid #c0ccda;
    margin: 5px 10px 10px 0px;
}
.ex_parent > div {
    padding: 10px;
    padding-left: 0;
    padding-top: 0;
}
.ex_input_f,
.ex_input_y {
    width: 100px;
}
.ex_input_tip {
    display: inline-block;
    font-size: 12px;
    color: red;
}
</style>
